﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="kod_vlaev_tunn_vastus", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(KodVlaevTunnVastus))]
    public class KodVlaevTunnVastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKodVlaevTunnVastus clazz;
        
        public KodVlaevTunnVastusSerializer(IKodVlaevTunnVastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("tunnistus");
            if (clazz.Tunnistus!=null) {
                global::Xtee.Core.SerializationMetadata metaTunnistus = this.GetMetaData(clazz.Tunnistus);
                Writer.WriteTypeAttribute(metaTunnistus.TypeQualifiedName.Namespace, metaTunnistus.TypeQualifiedName.Name);
                metaTunnistus.NewSerializer(clazz.Tunnistus).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tunnistus");
            }
            Writer.WriteEndElement();
            if (clazz.Teade!=null) {
                Writer.WriteStartElement("teade");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Teade))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "tunnistus")) {
                goto tunnistus;
            }
            else {
                if ((Reader.LocalName == "teade")) {
                    goto teade;
                }
                else {
                    return;
                }
            }
        tunnistus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kod_vlaev_tunn_vastus>tunnistus");
            }
            global::Xtee.Core.SerializationMetadata metaTunnistus = this.GetMetaData<KodVlaevTunnVastus.ITunnistusType>(Reader, ">>kod_vlaev_tunn_vastus>tunnistus", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
            clazz.Tunnistus = metaTunnistus.NewEntity<KodVlaevTunnVastus.ITunnistusType>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("tunnistus");
                metaTunnistus.NewSerializer(clazz.Tunnistus).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        teade:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kod_vlaev_tunn_vastus>teade");
            }
            clazz.Teade = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("teade")).Value;
            goto START;
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>kod_vlaev_tunn_vastus>tunnistus", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(KodVlaevTunnVastus.TunnistusType))]
        public class TunnistusTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected KodVlaevTunnVastus.ITunnistusType clazz;
            
            public TunnistusTypeSerializer(KodVlaevTunnVastus.ITunnistusType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                for (int x = 0; ((clazz.Tunnistus != null) 
                            && (x < clazz.Tunnistus.Count)); x = (x + 1)) {
                    if (clazz.Tunnistus[x]!=null) {
                        Writer.WriteStartElement("tunnistus");
                        global::Xtee.Core.SerializationMetadata metaTunnistus = this.GetMetaData(clazz.Tunnistus[x]);
                        Writer.WriteTypeAttribute(metaTunnistus.TypeQualifiedName.Namespace, metaTunnistus.TypeQualifiedName.Name);
                        metaTunnistus.NewSerializer(clazz.Tunnistus[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="tunnistus") {
                    clazz.Tunnistus = new System.Collections.Generic.List<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IVlaevTunnistus>();
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "tunnistus")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>kod_vlaev_tunn_vastus>tunnistus>tunnistus");
                        }
                        global::Xtee.Core.SerializationMetadata metaTunnistus = this.GetMetaData<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IVlaevTunnistus>(Reader, "vlaev_tunnistus", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                        global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IVlaevTunnistus item = metaTunnistus.NewEntity<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IVlaevTunnistus>();
                        clazz.Tunnistus.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("tunnistus");
                            metaTunnistus.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                }
            }
        }
    }
}
